//          https://ac.nowcoder.com/acm/problem/227310




#include <iostream>
#include <cmath>
using namespace std;

int T;
long long a, b;

bool isPrime(long long number)
{
    if (number < 2)
        return false;
    if (number == 2)
        return true;
    if (number % 2 == 0)
        return false;
    for (int i = 3; i <= sqrt(number); i += 2)
        if (number % i == 0)
            return false;
    return true;
}

int main()
{
    cin >> T;

    while (T--)
    {
        cin >> a >> b;
        long long x = a * b;
        cout << (isPrime(x) ? "YES" : "NO") << endl;
    }

    return 0;
}